<?php 
class BlogModel extends Model{
	public $table='blog_blog';
	//获得所有栏目
	public function addBlog(){
		//有上传缩略图文件时处理上传文件
		if (!empty($_FILES['thumb']['name'])) {
			$upload=new Upload;
			$files=$upload->upload();
			$_POST['thumb']=$files[0]['path'];
		}
		// 发表时间
		$_POST['addtime']=time();
		 return $this->insert($_POST);
	}
	// 修改博客
	public function editBlog(){
		// 有上传缩略图文件时处理文件
		if (!empty($_FILES['thumb']['name'])) {
			if (is_file($_POST['thumb'])) {
				unlink($_POST['thumb']);
			}
			$upload=new Upload;
			$files=$upload->upload();
			$_POST['thumb']=$files[0]['path'];
		}
		$_POST['addTime']=time();
		return $this->where("bid={$_POST['bid']}")->update($_POST);
	}
	// 查看博客

	public function getall(){
		$result=$this->query("select count(*) as c from blog_blog");
		// p($result);exit;
		$page=new Page($result[0]['c'],10);
		$pageStr=$page->show();//显示页面
		$limit=$page->limit();
		$sql ="select * from blog_blog b  join blog_category c on b.cid=c.cid order by bid desc  LIMIT {$limit} ";
		$blog=$this->query($sql);
		return array('blog'=>$blog,'page'=>$pageStr);
	}
}

 ?>